package com.slanmao.service.impl;

import com.slanmao.entity.AreaServ;
import com.slanmao.entity.AreaServExample;
import com.slanmao.mapper.AreaServDAO;
import com.slanmao.service.AreaServService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <CODE>AreaServServiceImpl</CODE>
 *
 * @author fenrir
 * @Date 18-11-5
 */

@Service
public class AreaServServiceImpl implements AreaServService {

    @Autowired
    AreaServDAO areaServDAO;

    @Override
    public AreaServ findByKeyWord(String keyword) {
        AreaServExample example = new AreaServExample();
        AreaServExample.Criteria city = example.createCriteria();
        city.andCityEqualTo(keyword);
        example.or(city);
        AreaServExample.Criteria province = example.createCriteria();
        province.andProvinceEqualTo(keyword);
        example.or(province);
        AreaServExample.Criteria district = example.createCriteria();
        district.andDistrictEqualTo(keyword);
        example.or(district);
        List<AreaServ> areaServs = areaServDAO.selectByExample(example);
        if (areaServs.size()>=1){
            return areaServs.get(0);
        }
        return null;
    }

    @Override
    public void uploadBatch(List<AreaServ> list) {
        areaServDAO.insertBatch(list);
    }
}
